package com.springday3aop.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class MyAdvice3 {
    @Pointcut("execution(boolean com.springday3aop.service.*Service.*(..))")
    private void servicePt() {
    }

    ;

    @Around("servicePt()")
    public Object trimStr(ProceedingJoinPoint pjp) throws Throwable {

//        获取原始方法的参数
        Object[] args = pjp.getArgs();
        for (int i = 0; i < args.length; i++) {
//            判断参数是不是字符串
            if (args[i].getClass().equals(String.class)) {
//                如果是字符串，就将字符串后面的空格去掉
                args[i] = args[i].toString().trim();
            }
        }
//        将修改后的参数传入到原始方法中
        Object ret = pjp.proceed(args);
        return ret;
    }
}
